{php $top_name=$cat.name;}{template "header.html"}

<div class="page-container">
    <div class="page-content-wrapper">
        <div class="page-content bg-b">
            <div class="bg-h">
                <div class="swiper-container">
                    <div class="swiper-wrapper">
                        {loop $thumb $i $t}
                        <div class="swiper-slide">
                            <img src="{dr_thumb($t.file, 450, 200)}" style="width:450px;height:200px" />
                        </div>
                        {/loop}
                    </div>
                    <div class="swiper-pagination"></div>
                </div>
                <link rel="stylesheet" href="{HOME_THEME_PATH}swiper/css/swiper.min.css">
                <script src="{HOME_THEME_PATH}swiper/js/swiper.min.js"></script>
                <script>
                    var swiper = new Swiper('.swiper-container', {
                        spaceBetween: 30,
                        autoplay: {
                            delay: 3500,
                            disableOnInteraction: false,
                        },
                        pagination: {
                            el: '.swiper-pagination',
                            clickable: true,
                        },
                    });
                </script>
                <div class="head-title">
                    <div class="news-title">
                        {$title}
                    </div>
                    <div class="news-title-btn">
                        <div class="left"><span class="price">￥<b id="dr_sku_price">{$order_price}</b>元</span>
                            {if !$order_shipping}<span class="ico s_mianyuyue display1">包邮</span>{/if}
                            {if !$order_status}<span class="ico s_tuijian display1">已下架</span>{/if}
                        </div>
                        <div class="right"><span class="num2">{dr_show_hits($id)}</span>人气<span class="line"></span><span class="num2">{$comments}</span>评论</div>
                    </div>
                </div>
            </div>

            <div class="container bg-h">
                <div class="news-keyword-tags margin-top-20">
                    <div class="left"><span class="xuan">已选</span></div>
                    <div class="left"><span class="xuan_value dr_sku_name_value">...</span></div>
                    <div class="right"><a class="xuan_btn" href="javascript:;" onclick="dr_shop_footer()"><i class="fa fa-angle-right"></i></a></div>
                    <div class="clear"></div>
                </div>
            </div>

            <div class="container bg-h">
                <div class="news-table margin-top-10">
                    <div class="title"><span>详细介绍</span></div>
                    <div class="content">
                        <div class="news-content">
                            {$content}
                        </div>
                        <div class="hide-news-content text-center">
                            <a>展开内容</a>
                        </div>
                    </div>
                </div>
            </div>

            <div class="container bg-h">
                <div class="news-table margin-top-10">
                    <div class="title"><span>商品属性</span></div>
                    <div class="content">
                        {php $sx = dr_mall_property_value($catid, $shangpinshuxing);}
                        <table cellpadding="0" cellspacing="1" width="100%" border="0" class="table table-bordered">
                            <tbody>
                            {loop $sx $name $value}
                            <tr>
                                <th class="tdTitle" colspan="2">{$name}</th>
                            </tr>
                            {loop $value $n $v}
                            <tr>
                                <td width="200" class="tdTitle">{$n}</td>
                                <td>
                                    {if is_array($v)}
                                    {implode(' ', $v)}
                                    {else}
                                    {$v}
                                    {/if}
                                </td>
                            </tr>
                            {/loop}
                            {/loop}
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>

            <div class="container bg-h">
                <div class="news-keyword-tags margin-top-10">
                    {loop $keyword_list $name $url}
                    <label>
                        <a href="{$url}" target="_blank">{$name}</a>
                    </label>
                    {/loop}
                </div>
            </div>



            <div class="container bg-h">
                <div class=" news-table" id="comment-post-div">
                    <div class="title"><span>网友评论</span></div>
                    <div class="nr">
                        {dr_module_comment(MOD_DIR, $id)}
                    </div>
                </div>
            </div>

        </div>
    </div>
</div>

<div class="footFixed" id="foot_btn_fixed">
    <div class="reply_hd clearfix display1" id="reply_hd">
        <ul>
            <li><a href="{MODULE_URL}" class="share">回首页</a></li>
            <li onclick="dr_module_favorite('{MOD_DIR}', '{$id}', 0);"><i style="font-size: 18px;" class="fa fa-heart"></i> <span  id="favorite">收藏</span></li>
            <li><i class="fa fa-shopping-cart" style="font-size: 18px;"></i> <a href="{dr_url('order/cart/index')}" id="shop_cart_num">-</a></li>
            <li><a href="javascript:;" onclick="dr_shop_footer()" id="openReply" class="btn"><i class="fa fa-plus"></i> 购买</a></li>
        </ul>
    </div>
</div>
<div class="detail_sku_v1_main hide" id="popupBuyArea">
    <div class="main" id="popupMain">
        <div class="header">
            <img alt="商品图" src="{dr_thumb($thumb[0], 100, 100)}" class="avt" id="popupImg">
            <p class="price" id="priceSale2">¥<b id="dr_sku_price2">{$order_price}</b></p>
            <p class="prop" id="popupSkuChoose"><span>已选</span> <i class="dr_sku_name_value">... </i></p>
            <a class="close" href="javascript:;" onclick="dr_shop_footer()" id="popupClose"><i class="fa fa-close"></i></a>
        </div>
        <div class="body">
            <div id="popupSkuArea">
                {if $order_specification}
                {php $sku = dr_get_spec_data($catid, $order_specification);}
                {loop $sku $oname $s}
                {if isset($order_specification['option'][$oname]) && $order_specification['option'][$oname]}
                <div class="sku_kind">{$s['name']}</div>
                <input class="dr_sku_value" id="dr_sku_{$oname}" oname="{$oname}" type="hidden" value="" />
                <div class="sku_choose dr_sku_{$oname} sku-value">
                    {loop $order_specification['option'][$oname] $val}
                    <span {if $sku[$oname]['type']=='color'} style="background-color:{php echo preg_match('/[a-z]+/', $val) ? $val : '#'.$val;}"{/if} id="dr_sku_value_{$val}" ovalue="{$val}" class="item" onclick="dr_sku_select_item(this, '{$oname}', '{$val}')" title="{$s['value'][$val]}">{if $sku[$oname]['type']=='color'}&nbsp;&nbsp;&nbsp;&nbsp;{else}{$s['value'][$val]}{/if}</span>
                    {/loop}
                </div>
                {/if}
                {/loop}
                {/if}
            </div>

            <div class="count_choose" id="popupCount">
                <div class="num_wrap_v2">
                    <span class="minus disable"   onclick="dr_sku_item_num(0)" id="minus1"><i class="row"></i></span>
                    <div class="text_wrap"><input class="text" type="tel" value="1" id="dr_sku_num"></div>
                    <span class="plus"  onclick="dr_sku_item_num(1)" id="plus1"><i class="row"></i><i class="col"></i></span>
                </div>
                <p class="count">库存 <em id="dr_sku_quantity" class="store">{$order_quantity}</em> </p>
            </div>
        </div>
        <div class="btns show" style="">
            <div class="btn yellow" id="addCart1" onclick="dr_cart()">加入购物车</div>
            <div class="btn red" id="buyBtn1" onclick="dr_buy()">立即购买</div>
        </div>
    </div>
</div>
<script>
function dr_shop_footer() {
    if ($('#popupBuyArea').hasClass('show')) {
        $('#popupBuyArea').addClass('hide');
        $('#popupBuyArea').removeClass('show');
    } else {
        $('#popupBuyArea').addClass('show');
        $('#popupBuyArea').removeClass('hide');
    }
}

{php $sku_sn = $sku_price = $sku_quantity = array();}
{loop $order_specification.value $iid $t}
{php $sku_price[$iid] = $t['price'];}
{php $sku_sn[$iid] = $t['sn'];}
{php $sku_quantity[$iid] = $t['quantity'];}
{/loop}
var sku_sn = {json_encode($sku_sn)};
var sku_price = {json_encode($sku_price)};
var sku_quantity = {json_encode($sku_quantity)};

// 商品数量加减选择
function dr_sku_item_num(op) {
    var num = parseInt($("#dr_sku_num").val());
    var _quantity = parseInt($("#dr_sku_quantity").html());
    if (isNaN(num) || num <= 1) num = 1;
    if (op) {
        // 加操作
        num++;
        if (num >= _quantity) num = _quantity;
    } else {
        // 减操作
        num--;
        if (isNaN(num) || num <= 1) num = 1;
    }
    $("#dr_sku_num").val(num);
}
// 购买商品
function dr_buy() {
    {if !$member}
    dr_login();
    return;
    {/if}
    var order = "{dr_url('order/home/index', array('mid'=>MOD_DIR, 'cid'=>$id))}";
    {if $order_specification}
    var i = 0;
    var sku = new Array();
    $(".dr_sku_value").each(function(){
        var id = $(this).val();
        if (id == "") {
            // 请勾选您要的商品信息
            dr_tips("请勾选您要的商品信息", 3);
            return;
        }
        sku[i] = id;
        i++;
    });
    order+= "&spec="+sku.join("_"); // 组合串联属性
    {/if}
    // 判断库存
    var _quantity = parseInt($("#dr_sku_quantity").html());
    if (isNaN(_quantity) || _quantity <= 0) {
        dr_tips("库存不足无法购买", 3);
        return;
    }
    var num = parseInt($("#dr_sku_num").val());
    order+= "&num="+num;
    location.href=order;
}
// 购物车
var is_cart = true;
function dr_cart() {
    if (!is_cart) {
        //alert('刷新后再试');
        //return;
    }
    var cart = "{dr_url('order/cart/add', array('mid'=>MOD_DIR, 'cid'=>$id))}";
    {if $order_specification}
    var i = 0;
    var sku = new Array();
    $(".dr_sku_value").each(function(){
        var id = $(this).val();
        if (id == "") {
            // 请勾选您要的商品信息
            dr_tips("请勾选您要的商品信息", 3);
            return;
        }
        sku[i] = id;
        i++;
    });
    cart+= "&spec="+sku.join("_");
    {/if}
    // 判断库存
    var _quantity = parseInt($("#dr_sku_quantity").html());
    if (isNaN(_quantity) || _quantity <= 0) {
        dr_tips("库存不足无法购买", 3);
        return;
    }
    var num = parseInt($("#dr_sku_num").val());
    cart+= "&num="+num;
    is_cart = false;
    $.ajax({type: "GET", url: cart, dataType:"jsonp",
        success: function (data) {
            if (data.status) {
                $("#shop_cart_num").html(data.code);
                dr_tips('添加成功，购车中共'+data.code+'件商品', 3, 1);
            } else {
                dr_tips(data.code);
                is_cart = true;
            }
        }
    });
}
// 按规则更新商品价格
function dr_sku_update_item() {
    var i = 0;
    var sku = new Array();
    var sku_name = new Array();
    // 遍历属性
    $(".dr_sku_value").each(function(){
        var id = $(this).val();
        if (id == "") return;
        sku[i] = id;
        sku_name[i] = $("#dr_sku_value_"+id).attr('title');
        i++;
    });
    var oname = sku.join("_"); // 组合串联属性
    var ovalue = sku_name.join("，"); // 组合串联属性name
    $(".dr_sku_name_value").html(ovalue);
    // 当全部勾选之后才更新商品价格与库存
    var _sn = sku_sn[oname];
    var _price = sku_price[oname];
    var _quantity = sku_quantity[oname];
    $("#dr_sku_price").html(price_float(_price));
    $("#dr_sku_price2").html(price_float(_price));
    $("#dr_sku_sn").html(_sn);
    if (_quantity) {
        $("#dr_sku_quantity").html(_quantity);
    } else {
        $("#dr_sku_quantity").html("库存不足");
    }
}
// 按规则选择商品
function dr_sku_select_item(_this, oname, val) {
    $(".dr_sku_"+oname+" > span").attr("class", "item");
    $(_this).attr("class", "active item");
    $("#dr_sku_"+oname).val(val);
    dr_sku_update_item();
}
function price_float(value){  //保留两位小数点
    if (!value) value = 0;
    value = Math.round(parseFloat(value) * 100) / 100;
    if (value.toString().indexOf(".") < 0) {
        value = value.toString() + ".00";
    }
    return value;
}
// 设置商品的默认规则
$(function(){
    $(".dr_sku_value").each(function(){
        var id = $(this).val();
        var oname = $(this).attr("oname");
        $(".dr_sku_"+oname+" > span").attr("class", "item");
        if (id) {
            $("#dr_sku_value_"+id).attr("class", "active item");
        } else {
            var _first = $(".dr_sku_"+oname+" span").first();
            var _iid = _first.attr("ovalue");
            _first.attr("class", "active item");
            $("#dr_sku_"+oname).val(_iid);
        }
        dr_sku_update_item();
    });
    $.ajax({
        type : "GET",
        url : "/index.php?s=order&c=cart&m=nums",
        dataType:"jsonp",  //请求支持jsonp
        success : function (json) {
        if (json.status == 1) {
            $("#shop_cart_num").html(json.code);
        }
    }
    });
});

</script>
{template "footer.html", "/"}